//
//  RouteTest.swift
//  SwiftUtils
//
//  Created by Ink on 2022/1/26.
//

import Foundation
import UIKit

enum LFCellType<T:UITableViewCell> {
    case cell(type: T, data: Any)
}

struct LFConciseCellItem<T:UITableViewCell> {
    
    let cellType: LFCellType<T>
    let handler: (() -> Void)?
    let enable: Bool
    
    init(enable: Bool = false, cellType:LFCellType<T>, handler: (() -> Void)? = nil) {
        self.cellType = cellType
        self.handler = handler
        self.enable = enable
    }
}

class BookDetailVC:UIViewController, UrlRouteProtocol {
    
    static var routeRegexKey: String {
        return RouteBookDetail
    }
    
    required init(params: [String : Any]?, captures: [String]?) {
        super.init(nibName: "", bundle: .main)
        params?.transitionString()?.mPrint()
        captures?.compactMap({ $0 }).joined(separator: "\n").mPrint()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


class BookReaderVC:UIViewController, UrlRouteProtocol {
    
    static var routeRegexKey: String {
        return RouteReaderTarget
    }
    
    required init(params: [String : Any]?, captures: [String]?) {
        super.init(nibName: "", bundle: .main)
        params?.transitionString()?.mPrint()
        captures?.compactMap({ $0 }).joined(separator: "\n").mPrint()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class RouteTest {
    
    func execute(viewController: UIViewController) {
        viewController.present(RouteTestViewController(), animated: true, completion: nil)
    }
}

class RouteTestViewController: UIViewController {
        
    let data = UIFont.familyNames

    override func viewDidLoad() {
        super.viewDidLoad()
        
        ZMRoute.initUrlRoute()
        let tableView = UITableView()
        view.addSubview(tableView)
        tableView.frame = view.bounds
                
        tableView.delegate = self
        tableView.dataSource = self
        
        "kpath://reader/123/chapterId/12345/markId/4/pageId/adad?a=1&b=2".openRoute()
        "kpath://book/1234".openRoute()
        
        RouteReader(bookId: 123, chapterId: 12345).openRoute(){ url in
            return url.merge(tabSelectedIndex: 0).merge(params: ["a":1,"b":2])
        }
    }
}

extension RouteTestViewController: UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cellId = "UITableViewCell"
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId) ?? UITableViewCell(style: .default, reuseIdentifier: cellId)
        
        let fontName = data[indexPath.row]
        cell.textLabel?.numberOfLines = 0
        cell.textLabel?.text = "\(fontName)"
            + "\n汉体书写信息技术标准相容"
        + "\n档案下载使用界面简单 \n支援服务升级资讯专业制作\n创意空间快速无线上网\n㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩\nAaBbCc ＡａＢｂＣｃ"
        cell.textLabel?.font = UIFont(name: fontName, size: 12)
        
        return cell
    }
}
